<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico" >
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/static/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/static/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="/static/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/style.css"/>   <#-- 自己的样式css -->
    <!--[if IE 6]>
    <script type="text/javascript" src="/static/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>管理员列表</title>
</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span>
    管理员管理 <span class="c-gray en">&gt;</span> 管理员列表
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>
<div class="page-container">
    <div class="text-c"> 日期范围：
        <input type="text" id="datemin" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}' })" class="input-text Wdate" style="width:140px;">
        -
        <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:140px;">
        <input type="text" class="input-text" style="width:250px" placeholder="输入管理员名称" id="adminName" name="">
        <button type="submit" class="btn btn-success" id="submitBtn" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l"><a href="javascript:;" id="admin_dels" class="btn btn-danger radius">
            <i class="Hui-iconfont">&#xe6e2;</i> 批量删除
        </a>
            <a href="javascript:;" id="add_400" class="btn btn-primary radius">
                <i class="Hui-iconfont">&#xe600;</i> 添加管理员
            </a>
        </span>
    </div>
    <table id="layAdmin_table" lay-filter="table"></table>
    <script type="text/html" id="tableBar">
        <a class="layui-btn layui-btn-warm layui-btn-xs" id="admin_stop" lay-event="stop">停用</a>
        <a class="layui-btn layui-btn-xs" id="admin_edit" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" id="admin_del" lay-event="del">删除</a>
    </script>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/static/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/static/layui/layui.js"></script>
<script type="text/javascript" src="/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/static/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="/static/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript">
    /*layui.use(['table','layer'], function(){
        var table = layui.table;
        var $ = layui.jquery;
        var layer = layui.layer;

        var tableIns = table.render({
            elem:"#layAdmin_table",
            url:"/dba/admin_list",
            page:true,
            request:{
                pageName:"pageNum",
                limitName:"pageSize"
            },
            cols:[[
                {type:'checkbox'},
                {field: 'aId', title: 'ID',align:"center",sort: true, width:70},
                {field: 'aUsername', title: '用户名', width:110},
                {field: 'aName', title: '真实姓名', width:90},
                {field: 'role', title: '角色', width:100},
                {field: 'aCreateTime', title: '创建时间',sort:true, width:180},
                {field: 'aUpdateTime', title: '更新时间',sort:true, width:180},
                {field: 'state', title: '是否已启用', width:100},
                {title:'操作',toolbar:'#tableBar'}
            ]],
        });

        table.on('tool(table)', function(obj){
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
/!*lay-event     console.log($("tbody").find(".laytable-cell-1-state").text()); *!/
            if(layEvent === 'stop'){ //停用
                layer.confirm('确认要停用吗？',function(index){
                    var id = data["aId"];
                    var adminState = obj.event;
                    var state;
                    if (adminState === "stop"){
                        state = 1 ;
                    }

                    $.ajax({
                        type:"POST",
                        url:"/dba/admin_state",
                        dataType:"json",
                        traditional:true,
                        data:{"id":id,"adminState":state},
                        success:function(data){
                            // 点击停用，将按钮改为open ，将已启用改为已停用，已停用的值来自于服务器
                            console.log(data);
                            $("#admin_stop").removeAttr("lay-event");
                            $("#admin_stop").attr("lay-event","open");
                            $("#admin_stop").attr("class","layui-btn layui-btn-normal layui-btn-xs").text("启用");;
                            $("tbody").find(".laytable-cell-1-state").text("已停用");
                            layer.close(index);
                        },
                        error:function(data){
                            console.log(data);
                        },
                    });
                });
            } else if(layEvent === 'open'){ //开启
                layer.confirm('确认要启用吗？',function(index){
                    var id = data["aId"];
                    var adminState = obj.event;
                    var state;
                    if (adminState === "open"){
                        state = 0 ;
                    }

                    $.ajax({
                        type:"POST",
                        url:"/dba/admin_state",
                        dataType:"json",
                        traditional:true,
                        data:{"id":id,"adminState":state},
                        success:function(data){
                            console.log(data);
                            $("#admin_stop").removeAttr("lay-event");
                            $("#admin_stop").attr("lay-event","stop");
                            $("#admin_stop").attr("class","layui-btn layui-btn-warm layui-btn-xs").text("停用");;
                            $("tbody").find(".laytable-cell-1-state").text("已启用");
                            layer.close(index);
                        },
                        error:function(data){
                            console.log(data);
                        },
                    });
                });
            } else if(layEvent === 'del'){ //删除
                layer.confirm('真的删除行么', function(index){
                    layer.close(index);
                    //向服务端发送删除指令
                    var jsonId = {"id":data["aId"].toString()};
                    $.ajax({
                        type:"POST",
                        url:"/dba/admin_deleteOne",
                        /!*contentType:"json",*!/
                        dataType:"json",
                        data:jsonId,
                        success:function(data){
                            console.log(data);
                            layer.msg("删除成功！",{icon:1});
                            obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                        },
                        error:function(data){
                            console.log(data);
                            layer.msg("服务器发生异常啦，码农们正在加紧抢修！",{icon:2});
                        }
                    });
                });
            } else if(layEvent === 'edit'){ //编辑
                var id = data["aId"].toString();
                layer.open({
                    type: 2,
                    area: [350+'px', 400 +'px'],
                    fix: false, //不固定
                    maxmin: true,
                    shade:0.4,
                    title: '编辑',
                    content: '/dba/admin_editPage/'+id,
                    end:function(){
                        tableIns.reload({
                            url:"/dba/admin_list"
                        });
                    }
                });


                /!*obj.update({
                    username: '123'
                    ,title: 'xxx'
                });*!/
            }
        });

        $("#submitBtn").click(function(){
            var dateMin = $("#datemin").val();
            var dateMax = $("#datemax").val();
            var adminName = $("#adminName").val();
            var conditionJso = "" ;
            if (dateMin == "" && dateMax == "" && adminName.trim() == ""){
                tableIns.reload({
                    url:"/dba/admin_list"
                });
                return ;
            }

            if(adminName.trim() != "" && dateMin == "" && dateMax == ""){
                conditionJso = {"adminName":adminName.trim()};
                tableIns.reload({
                    url:"/dba/condition_query",
                    where:conditionJso
                });
            }

            if(adminName.trim() == "" && dateMin != "" && dateMax != ""){
                conditionJso = {"dateMin":dateMin,"dateMax":dateMax};
                tableIns.reload({
                    url:"/dba/condition_query",
                    where:conditionJso
                });
            }

            if(dateMin != "" && dateMax != "" && adminName.trim() != ""){
                conditionJso = {"dateMin":dateMin,"dateMax":dateMax,"adminName":adminName.trim()};
                tableIns.reload({
                    url:"/dba/condition_query",
                    where:conditionJso
                });

            }
        });

        $("#add_400").click(function(){
            layer.open({
                type: 2,
                area: [380+'px', 400 +'px'],
                fix: false, //不固定
                maxmin: true,
                shade:0.4,
                title: '添加管理员',
                content: '/dba/admin-addPage',
                end:function(){
                    tableIns.reload({
                        url:"/dba/admin_list"
                    });
                }
            });
        });

        /!* 监听复选框 *!/
        /!* 删除多个 *!/
        var idArray = new Array();
        table.on("checkbox(table)",function(obj){
            var data = obj.data ;
            var checkStatus = obj.checked; //true || false
            var checkType = obj.type ; // one || all
            if (checkStatus){   //已经被选择状态
                var id = data["aId"];
                idArray.push(id);
            }
        });
        $("#admin_dels").click(function(obj){
            layer.confirm("确认删除吗?",function(index){
                var idArrayJson = {"id":idArray,"del":1};
                $.ajax({
                    type: 'POST',
                    url: '/dba/admin_delete',
                    dataType:"json",
                    traditional:true,
                    data:idArrayJson,
                    success: function(data){
                        idArray.slice(0,idArray.length);
                        console.log(data.msg);
                        if(data.msg === '不可删除'){
                            layer.msg("您不可以删除这条记录");
                        }
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                        layer.close(index);
                        tableIns.reload({
                            url:"/dba/admin_list"
                        });
                    },
                    error:function(data) {
                        idArray.slice(0,idArray.length);
                        console.log(data.msg);
                        layer.close(index);
                    },
                });
            });
        });
    });*/

    /*$.ajax({
                type:"GET",
                url:"/dba/condition_query",
                contentType:"json",
                dataType:"json",
                data:conditionJso,
                success:function(data){
                    console.log(data);
                },
                error:function(data){
                    console.log(data);
                }
            });*/
    /*
        参数解释：
        title	标题
        url		请求的url
        id		需要操作的数据id
        w		弹出层宽度（缺省调默认值）
        h		弹出层高度（缺省调默认值）
    */
</script>
</body>
</html>